#!/bin/bash
# Gitee 镜像源配置脚本

echo "🇨🇳 配置国内镜像源..."

# 备份原始源文件
sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak

# 使用阿里云 Ubuntu 镜像源
sudo tee /etc/apt/sources.list << 'APTEOF'
deb http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
APTEOF

# 更新源
sudo apt-get update

# 配置 Git 使用 Gitee 镜像
git config --global url."https://gitee.com/".insteadOf "https://github.com/"
git config --global url."git@gitee.com:".insteadOf "git@github.com:"

# 配置 pip 清华源
mkdir -p ~/.pip
cat > ~/.pip/pip.conf << 'PIPEOF'
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
extra-index-url = 
    https://mirrors.aliyun.com/pypi/simple/
trusted-host = 
    pypi.tuna.tsinghua.edu.cn
    mirrors.aliyun.com
timeout = 120
PIPEOF

# 配置 npm 淘宝源（如果有需要）
if command -v npm &> /dev/null; then
    npm config set registry https://registry.npmmirror.com
fi

echo "✅ 镜像源配置完成"
echo "   - APT: 阿里云"
echo "   - PIP: 清华大学"
echo "   - Git: Gitee 镜像"
